<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
    <title>Simple GSP page</title>

    <!-- Required CSS -->
    <link type="text/css" rel="stylesheet" href="http://yui.yahooapis.com/2.7.0/build/treeview/assets/skins/sam/treeview.css">
    <!-- Optional CSS for for date editing with Calendar-->
    <link type="text/css" rel="stylesheet" href="http://yui.yahooapis.com/2.7.0/build/calendar/assets/skins/sam/calendar.css">

    <!-- Dependency source file -->
    <script src="http://yui.yahooapis.com/2.7.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <!-- Optional dependency source file -->
    <script src="http://yui.yahooapis.com/2.7.0/build/animation/animation-min.js" type="text/javascript"></script>
    <!-- Optional dependency source file for date editing with Calendar-->
    <script src="http://yui.yahooapis.com/2.7.0/build/calendar/calendar.js"></script>

    <!-- TreeView source file -->
    <script src="http://yui.yahooapis.com/2.7.0/build/treeview/treeview-min.js"></script>
</head>
<body>
<h3>Test page for YUI treeview (json based?)</h3>

<div id="treeDiv1"></div>

<script type="text/javascript">
    var tree;
    function treeInit() {
        tree = new YAHOO.widget.TreeView("treeDiv1");
        tree.setDynamicLoad(loadDataForNode);

        var root = tree.getRoot();

        var myobj = { label: "mylabel1", id:"myid1" } ;
        var tmpNode = new YAHOO.widget.TextNode(myobj, root, false);

        tree.render();
    }

    function loadDataForNode(node, onCompleteCallback) {
        var id = node.data.id;

        // TODO -- need help getting data from grails controller: YuiController (json? xml? other?)
        // -- code to get your data, possibly using Connect --
        var tmpNode = new YAHOO.widget.TextNode(id + "label1", node, false);
        tmpNode = new YAHOO.widget.TextNode(id + "label2", node, false);

        // Be sure to notify the TreeView component when the data load is complete
        onCompleteCallback();
    }

    // am I the only noob that missed the fact that one needs to _actually_ call treeInit()???
    // I found that in _none_ of the examples... makes perfect sense in hindsight, but really stumped me and my noob-javascript skills
    treeInit()
    
</script>

</body>

</html>